Repository navigation
Add ECoG encoding support, unified CLI, and end-to-end tests - #12
Open
aadhavthaniga wants to merge 9 commits into
Open
aadhavthaniga wants to merge 9 commits into
aadhavthaniga wants to merge 9 commits into
Conversation
aadhavthaniga
marked this pull request as ready for review
October 13, 2026 22:38
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR now has three parts, each building on the previous one: the end-to-end test suite and shared fixes, continuous ECoG encoding support, and ECoG support in the
unified.pyCLI. The fMRI CLI's effective defaults are unchanged.1. End-to-end tests and shared fixes
Synthetic (
tests/test_pipeline_synthetic.py, offline): plants a signal at FIR lags 2-3 in 10 vertices. It checks recovery, the lag-specific kernel, FDR selection, FIR causality, no held-out leakage, and determinism. It also checks downsampler and FIR outputs against independent reference implementations.Golden (
tests/test_golden_lebel.py, opt-in): pinstrain_simple.py's wordrate results on the LeBel UTS03 assembly. It skips unlessLITCODER_LEBEL_ASSEMBLYpoints at the file. Tolerances come from measured CPU/MPS/cross-library variance (tests/fixtures/golden_lebel_uts03.json).Folding and shared fixes:
encoding/models/folding.py:trim_sizeand passes fold arguments by keyword.NestedCVModel:ActivationCache: cache keys cover the hook type and the stimuli, and a metadata mismatch raises.AbstractTrainerrefuses to truncate feature families with different row counts.AbstractTrainerandUnifiedTrainer.NestedCVModel.predict_fold.NestedCVModelaccepts supplied scikit-learn regressors and pipelines (encoding/models/estimator.py).train_simple.pyreads the assembly path fromLITCODER_LEBEL_ASSEMBLY, falling back to the existing path.Found along the way:
average,sum,last) misreadsplit_indicesand return about n_words rows. This is marked as a strict xfail.2. Continuous ECoG encoding
Assembly (
encoding/assembly/ecog_processor.py):ECoGAssemblyGeneratorreads a version-1ecog.jsonmanifest, or takes recording mappings directly. It validates:sampling_rate_hzvalid_samples, optionalunknown_samples, and invalid intervals that must agree with the masksInvalid rows and the original clocks are kept rather than dropped. It is also reachable through
AssemblyGenerator.generate_assembly("ecog", …), which rejects fMRI-only arguments such astr, volume and masks.Feature alignment and temporal expansion (
encoding/ecog_temporal.py):feature_specsmethod:word_sum,word_mean,word_last) aggregate events into half-open neural bins;words_per_bin,words_per_second) give word counts per bin or per second;speech_linearinterpolates mapped speech frames, with a maximum gap.delays_s) and rounded to sample offsets, with ties away from zero. Negative delays requireretrospective=True.memory_budget_bytes) estimates the expanded design and the major ridge arrays before fitting.Training:
AbstractTrainerroutes assemblies withmodality == "ecog"to this preparation (fir_delays=None,downsampler=None, empty trimming,ecog_temporal_config), then fits the existingNestedCVModel. ECoG does not use fMRI TR downsampling, FIR expansion, trimming, or per-story z-scoring.3. ECoG temporal cross-validation and safeguards
blocked: contiguous held-out blocks in recording/grid order.recording: held-out recordings.diagnostic_in_sample: one in-sample fit with one fixed positive ridge alpha. It is an engineering fit/replay check and emits no held-out metrics.folding_type,chunk_length,groups), missing preprocessing support for held-out evaluation, fold counts or an embargo under the diagnostic protocol, and duplicate realized delays are all rejected.inference_status="not_assessed". No p-values, FDR or significance masks are produced. Excluding dependencies does not establish independence between samples.4. ECoG in the
unified.pyCLI (new in this update)--dataset_type ecogwith--ecog_config(a JSON file holding the existingecog_temporal_config) and--alphas.UnifiedTrainer.setup_models(unchanged) for extractors and the model, andAbstractTrainer's ECoG branch. There is no second CLI framework, andUnifiedTraineris not modified.--tr,--ndelays, trimming, downsampling,--folding_type,--chunk_length,--story_idx,--story_order,--use_volume.--ecog_configand--alphasare rejected for fMRI.--tr/--ndelays/--lookbackrequirements are now applied after parsing. Effective fMRI configs are identical to the previous CLI (pinned by a snapshot test), and missing required options still exit with code 2.metadata["run_config"]: the effective CLI settings, the full temporal config, fit options, the encoding model, and SHA-256 hashes of the config andecog.json. File names are stored rather than absolute paths.5. Regression testing and verification
New
tests/test_unified_ecog_cli.py(23 tests, synthetic and offline):[0, 0.1, 0.2]s map to offsets[0, 1, 2], and declared gap rows are excluded.structure_dataandUnifiedTrainerpreparation patched to fail.main()still constructingUnifiedTrainerwith the unchanged config.unified.pyon synthetic data with wandb disabled.Verification on this branch:
pytest testsgives 165 passed, 4 skipped, 3 xfailed. A manual synthetic CLI run exits 0 and saves results.Known limitations and skipped tests
LITCODER_LEBEL_ASSEMBLYwas not set; that fixture is 2.8 GB. The golden path (train_simple.pythroughAbstractTrainer) is not changed by the CLI update.--context_type: it has no effect when the manifest supplies precomputed stimuli.ecog.jsonbut not the.npyfiles it references.ValueErrorfrom the ECoG preparation step, not as argparse errors.tensorboardlogger backend needstensorboardinstalled. Tests stub the loggers, and the subprocess smoke test uses wandb in disabled mode.